
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 10/05/2012 14:39:28
-- Generated from EDMX file: D:\Personal\Special\Code\Visual Studio 2010\Projects\SupportSystem\SupportSystem\SupportSystemDB\SupportModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [C345526_support];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[C345526_bondo2].[FK_Member_College]', 'F') IS NOT NULL
    ALTER TABLE [C345526_bondo2].[Member] DROP CONSTRAINT [FK_Member_College];
GO
IF OBJECT_ID(N'[C345526_bondo2].[FK_Member_Committee]', 'F') IS NOT NULL
    ALTER TABLE [C345526_bondo2].[Member] DROP CONSTRAINT [FK_Member_Committee];
GO
IF OBJECT_ID(N'[C345526_bondo2].[FK_Member_Position]', 'F') IS NOT NULL
    ALTER TABLE [C345526_bondo2].[Member] DROP CONSTRAINT [FK_Member_Position];
GO
IF OBJECT_ID(N'[C345526_bondo2].[FK_Member_University]', 'F') IS NOT NULL
    ALTER TABLE [C345526_bondo2].[Member] DROP CONSTRAINT [FK_Member_University];
GO
IF OBJECT_ID(N'[C345526_bondo2].[FK_memberContacts_contactType]', 'F') IS NOT NULL
    ALTER TABLE [C345526_bondo2].[Contact] DROP CONSTRAINT [FK_memberContacts_contactType];
GO
IF OBJECT_ID(N'[C345526_bondo2].[FK_memberContacts_member]', 'F') IS NOT NULL
    ALTER TABLE [C345526_bondo2].[Contact] DROP CONSTRAINT [FK_memberContacts_member];
GO
IF OBJECT_ID(N'[C345526_bondo2].[FK_Message_Member]', 'F') IS NOT NULL
    ALTER TABLE [C345526_bondo2].[Message] DROP CONSTRAINT [FK_Message_Member];
GO
IF OBJECT_ID(N'[C345526_bondo2].[FK_Message_Thread]', 'F') IS NOT NULL
    ALTER TABLE [C345526_bondo2].[Message] DROP CONSTRAINT [FK_Message_Thread];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[FK_Participate_Committee]', 'F') IS NOT NULL
    ALTER TABLE [SupportModelStoreContainer].[Participate] DROP CONSTRAINT [FK_Participate_Committee];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[FK_Participate_Event]', 'F') IS NOT NULL
    ALTER TABLE [SupportModelStoreContainer].[Participate] DROP CONSTRAINT [FK_Participate_Event];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[FK_Participate_Member]', 'F') IS NOT NULL
    ALTER TABLE [SupportModelStoreContainer].[Participate] DROP CONSTRAINT [FK_Participate_Member];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[FK_Participate_PositionType]', 'F') IS NOT NULL
    ALTER TABLE [SupportModelStoreContainer].[Participate] DROP CONSTRAINT [FK_Participate_PositionType];
GO
IF OBJECT_ID(N'[C345526_bondo2].[FK_Quote_Member]', 'F') IS NOT NULL
    ALTER TABLE [C345526_bondo2].[Quote] DROP CONSTRAINT [FK_Quote_Member];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[FK_Recieve_Member]', 'F') IS NOT NULL
    ALTER TABLE [SupportModelStoreContainer].[Receive] DROP CONSTRAINT [FK_Recieve_Member];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[FK_Recieve_Message]', 'F') IS NOT NULL
    ALTER TABLE [SupportModelStoreContainer].[Receive] DROP CONSTRAINT [FK_Recieve_Message];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[FK_Role_Event]', 'F') IS NOT NULL
    ALTER TABLE [SupportModelStoreContainer].[Role] DROP CONSTRAINT [FK_Role_Event];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[FK_Role_Member]', 'F') IS NOT NULL
    ALTER TABLE [SupportModelStoreContainer].[Role] DROP CONSTRAINT [FK_Role_Member];
GO
IF OBJECT_ID(N'[C345526_bondo2].[FK_Thread_ThreadType]', 'F') IS NOT NULL
    ALTER TABLE [C345526_bondo2].[Thread] DROP CONSTRAINT [FK_Thread_ThreadType];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[C345526_bondo2].[College]', 'U') IS NOT NULL
    DROP TABLE [C345526_bondo2].[College];
GO
IF OBJECT_ID(N'[C345526_bondo2].[Committee]', 'U') IS NOT NULL
    DROP TABLE [C345526_bondo2].[Committee];
GO
IF OBJECT_ID(N'[C345526_bondo2].[Contact]', 'U') IS NOT NULL
    DROP TABLE [C345526_bondo2].[Contact];
GO
IF OBJECT_ID(N'[C345526_bondo2].[ContactType]', 'U') IS NOT NULL
    DROP TABLE [C345526_bondo2].[ContactType];
GO
IF OBJECT_ID(N'[C345526_bondo2].[Event]', 'U') IS NOT NULL
    DROP TABLE [C345526_bondo2].[Event];
GO
IF OBJECT_ID(N'[C345526_bondo2].[Member]', 'U') IS NOT NULL
    DROP TABLE [C345526_bondo2].[Member];
GO
IF OBJECT_ID(N'[C345526_bondo2].[Message]', 'U') IS NOT NULL
    DROP TABLE [C345526_bondo2].[Message];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[Participate]', 'U') IS NOT NULL
    DROP TABLE [SupportModelStoreContainer].[Participate];
GO
IF OBJECT_ID(N'[C345526_bondo2].[Position]', 'U') IS NOT NULL
    DROP TABLE [C345526_bondo2].[Position];
GO
IF OBJECT_ID(N'[C345526_bondo2].[Quote]', 'U') IS NOT NULL
    DROP TABLE [C345526_bondo2].[Quote];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[Receive]', 'U') IS NOT NULL
    DROP TABLE [SupportModelStoreContainer].[Receive];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[Role]', 'U') IS NOT NULL
    DROP TABLE [SupportModelStoreContainer].[Role];
GO
IF OBJECT_ID(N'[C345526_bondo2].[Thread]', 'U') IS NOT NULL
    DROP TABLE [C345526_bondo2].[Thread];
GO
IF OBJECT_ID(N'[C345526_bondo2].[ThreadType]', 'U') IS NOT NULL
    DROP TABLE [C345526_bondo2].[ThreadType];
GO
IF OBJECT_ID(N'[C345526_bondo2].[University]', 'U') IS NOT NULL
    DROP TABLE [C345526_bondo2].[University];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[vContact]', 'U') IS NOT NULL
    DROP TABLE [SupportModelStoreContainer].[vContact];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[vMember]', 'U') IS NOT NULL
    DROP TABLE [SupportModelStoreContainer].[vMember];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[vMessage]', 'U') IS NOT NULL
    DROP TABLE [SupportModelStoreContainer].[vMessage];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[vParticipate]', 'U') IS NOT NULL
    DROP TABLE [SupportModelStoreContainer].[vParticipate];
GO
IF OBJECT_ID(N'[SupportModelStoreContainer].[vQuote]', 'U') IS NOT NULL
    DROP TABLE [SupportModelStoreContainer].[vQuote];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'vContacts'
CREATE TABLE [dbo].[vContacts] (
    [Type] nvarchar(50)  NOT NULL,
    [Id] int  NOT NULL,
    [MemberId] int  NOT NULL,
    [TypeId] int  NOT NULL,
    [Value] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'vMembers'
CREATE TABLE [dbo].[vMembers] (
    [Id] int  NOT NULL,
    [FullName] nvarchar(50)  NOT NULL,
    [Gender] int  NOT NULL,
    [CvFile] nvarchar(max)  NOT NULL,
    [AcademicYear] nvarchar(50)  NOT NULL,
    [IsActive] bit  NOT NULL,
    [LargeImage] nvarchar(max)  NULL,
    [CommitteeName] nvarchar(50)  NULL,
    [PositionName] nvarchar(50)  NULL,
    [CollegeName] nvarchar(50)  NULL,
    [UniversityName] nvarchar(50)  NULL,
    [UserName] nvarchar(50)  NOT NULL,
    [SmallImage] nvarchar(max)  NULL,
    [Expr1] nvarchar(max)  NULL,
    [BirthDate] datetime  NULL,
    [JoinedDate] datetime  NULL
);
GO

-- Creating table 'vParticipates'
CREATE TABLE [dbo].[vParticipates] (
    [PositionName] nvarchar(50)  NOT NULL,
    [CommitteeName] nvarchar(50)  NOT NULL,
    [EventName] nvarchar(50)  NOT NULL,
    [EventId] int  NOT NULL,
    [MemberId] int  NOT NULL
);
GO

-- Creating table 'vQuotes'
CREATE TABLE [dbo].[vQuotes] (
    [Id] int  NOT NULL,
    [MemberId] int  NOT NULL,
    [Sentence] nvarchar(max)  NOT NULL,
    [MemberName] nvarchar(50)  NOT NULL,
    [AddedDate] datetime  NOT NULL
);
GO

-- Creating table 'Colleges'
CREATE TABLE [dbo].[Colleges] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Committees'
CREATE TABLE [dbo].[Committees] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Logo] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Contacts'
CREATE TABLE [dbo].[Contacts] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [MemberId] int  NOT NULL,
    [TypeId] int  NOT NULL,
    [Value] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'ContactTypes'
CREATE TABLE [dbo].[ContactTypes] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Events'
CREATE TABLE [dbo].[Events] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Logo] nvarchar(max)  NOT NULL,
    [StartDate] datetime  NOT NULL,
    [EndDate] datetime  NOT NULL
);
GO

-- Creating table 'Members'
CREATE TABLE [dbo].[Members] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Gender] int  NOT NULL,
    [CollegeId] int  NOT NULL,
    [UniversityId] int  NOT NULL,
    [CvFile] nvarchar(max)  NOT NULL,
    [AcademicYear] nvarchar(50)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [UserName] nvarchar(50)  NOT NULL,
    [IsActive] bit  NOT NULL,
    [LargeImage] nvarchar(max)  NULL,
    [SmallImage] nvarchar(max)  NULL,
    [CurrentPostionId] int  NULL,
    [CurrentCommitteeId] int  NULL,
    [BirthDate] datetime  NULL,
    [JoinedDate] datetime  NULL
);
GO

-- Creating table 'Participates'
CREATE TABLE [dbo].[Participates] (
    [MemberId] int  NOT NULL,
    [EventId] int  NOT NULL,
    [PositionId] int  NOT NULL,
    [CommitteeId] int  NOT NULL
);
GO

-- Creating table 'Positions'
CREATE TABLE [dbo].[Positions] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Quotes'
CREATE TABLE [dbo].[Quotes] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [MemberId] int  NOT NULL,
    [Sentence] nvarchar(max)  NOT NULL,
    [AddedDate] datetime  NOT NULL
);
GO

-- Creating table 'Roles'
CREATE TABLE [dbo].[Roles] (
    [MemberId] int  NOT NULL,
    [EventId] int  NOT NULL,
    [IsManager] bit  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Universities'
CREATE TABLE [dbo].[Universities] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Messages'
CREATE TABLE [dbo].[Messages] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Subject] nvarchar(50)  NOT NULL,
    [Body] nvarchar(max)  NOT NULL,
    [ThreadId] int  NOT NULL,
    [SenderId] int  NOT NULL,
    [SentDate] datetime  NOT NULL
);
GO

-- Creating table 'Threads'
CREATE TABLE [dbo].[Threads] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [TypeId] int  NOT NULL
);
GO

-- Creating table 'ThreadTypes'
CREATE TABLE [dbo].[ThreadTypes] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Receives'
CREATE TABLE [dbo].[Receives] (
    [MsgId] int  NOT NULL,
    [MemberId] int  NOT NULL,
    [IsOpened] bit  NOT NULL,
    [OpenedDate] datetime  NOT NULL
);
GO

-- Creating table 'vMessages'
CREATE TABLE [dbo].[vMessages] (
    [Subject] nvarchar(50)  NOT NULL,
    [Body] nvarchar(max)  NOT NULL,
    [Id] int  NOT NULL,
    [SentDate] datetime  NOT NULL,
    [SenderName] nvarchar(50)  NOT NULL,
    [CommitteeName] nvarchar(50)  NOT NULL,
    [PositionName] nvarchar(50)  NOT NULL,
    [SenderId] int  NOT NULL,
    [ThreadId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Type], [Id], [MemberId], [TypeId], [Value] in table 'vContacts'
ALTER TABLE [dbo].[vContacts]
ADD CONSTRAINT [PK_vContacts]
    PRIMARY KEY CLUSTERED ([Type], [Id], [MemberId], [TypeId], [Value] ASC);
GO

-- Creating primary key on [Id], [FullName], [Gender], [CvFile], [AcademicYear], [IsActive], [UserName] in table 'vMembers'
ALTER TABLE [dbo].[vMembers]
ADD CONSTRAINT [PK_vMembers]
    PRIMARY KEY CLUSTERED ([Id], [FullName], [Gender], [CvFile], [AcademicYear], [IsActive], [UserName] ASC);
GO

-- Creating primary key on [PositionName], [CommitteeName], [EventName], [EventId], [MemberId] in table 'vParticipates'
ALTER TABLE [dbo].[vParticipates]
ADD CONSTRAINT [PK_vParticipates]
    PRIMARY KEY CLUSTERED ([PositionName], [CommitteeName], [EventName], [EventId], [MemberId] ASC);
GO

-- Creating primary key on [Id], [MemberId], [Sentence], [MemberName], [AddedDate] in table 'vQuotes'
ALTER TABLE [dbo].[vQuotes]
ADD CONSTRAINT [PK_vQuotes]
    PRIMARY KEY CLUSTERED ([Id], [MemberId], [Sentence], [MemberName], [AddedDate] ASC);
GO

-- Creating primary key on [Id] in table 'Colleges'
ALTER TABLE [dbo].[Colleges]
ADD CONSTRAINT [PK_Colleges]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Committees'
ALTER TABLE [dbo].[Committees]
ADD CONSTRAINT [PK_Committees]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Contacts'
ALTER TABLE [dbo].[Contacts]
ADD CONSTRAINT [PK_Contacts]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ContactTypes'
ALTER TABLE [dbo].[ContactTypes]
ADD CONSTRAINT [PK_ContactTypes]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Events'
ALTER TABLE [dbo].[Events]
ADD CONSTRAINT [PK_Events]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Members'
ALTER TABLE [dbo].[Members]
ADD CONSTRAINT [PK_Members]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [MemberId], [EventId], [PositionId], [CommitteeId] in table 'Participates'
ALTER TABLE [dbo].[Participates]
ADD CONSTRAINT [PK_Participates]
    PRIMARY KEY CLUSTERED ([MemberId], [EventId], [PositionId], [CommitteeId] ASC);
GO

-- Creating primary key on [Id] in table 'Positions'
ALTER TABLE [dbo].[Positions]
ADD CONSTRAINT [PK_Positions]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Quotes'
ALTER TABLE [dbo].[Quotes]
ADD CONSTRAINT [PK_Quotes]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [MemberId], [EventId], [IsManager], [Description] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [PK_Roles]
    PRIMARY KEY CLUSTERED ([MemberId], [EventId], [IsManager], [Description] ASC);
GO

-- Creating primary key on [Id] in table 'Universities'
ALTER TABLE [dbo].[Universities]
ADD CONSTRAINT [PK_Universities]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Messages'
ALTER TABLE [dbo].[Messages]
ADD CONSTRAINT [PK_Messages]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Threads'
ALTER TABLE [dbo].[Threads]
ADD CONSTRAINT [PK_Threads]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ThreadTypes'
ALTER TABLE [dbo].[ThreadTypes]
ADD CONSTRAINT [PK_ThreadTypes]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [MsgId], [MemberId], [IsOpened], [OpenedDate] in table 'Receives'
ALTER TABLE [dbo].[Receives]
ADD CONSTRAINT [PK_Receives]
    PRIMARY KEY CLUSTERED ([MsgId], [MemberId], [IsOpened], [OpenedDate] ASC);
GO

-- Creating primary key on [Subject], [Body], [Id], [SentDate], [SenderName], [CommitteeName], [PositionName], [SenderId], [ThreadId] in table 'vMessages'
ALTER TABLE [dbo].[vMessages]
ADD CONSTRAINT [PK_vMessages]
    PRIMARY KEY CLUSTERED ([Subject], [Body], [Id], [SentDate], [SenderName], [CommitteeName], [PositionName], [SenderId], [ThreadId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [CollegeId] in table 'Members'
ALTER TABLE [dbo].[Members]
ADD CONSTRAINT [FK_Member_College]
    FOREIGN KEY ([CollegeId])
    REFERENCES [dbo].[Colleges]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Member_College'
CREATE INDEX [IX_FK_Member_College]
ON [dbo].[Members]
    ([CollegeId]);
GO

-- Creating foreign key on [CurrentCommitteeId] in table 'Members'
ALTER TABLE [dbo].[Members]
ADD CONSTRAINT [FK_Member_Committee]
    FOREIGN KEY ([CurrentCommitteeId])
    REFERENCES [dbo].[Committees]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Member_Committee'
CREATE INDEX [IX_FK_Member_Committee]
ON [dbo].[Members]
    ([CurrentCommitteeId]);
GO

-- Creating foreign key on [CommitteeId] in table 'Participates'
ALTER TABLE [dbo].[Participates]
ADD CONSTRAINT [FK_Participate_Committee]
    FOREIGN KEY ([CommitteeId])
    REFERENCES [dbo].[Committees]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Participate_Committee'
CREATE INDEX [IX_FK_Participate_Committee]
ON [dbo].[Participates]
    ([CommitteeId]);
GO

-- Creating foreign key on [TypeId] in table 'Contacts'
ALTER TABLE [dbo].[Contacts]
ADD CONSTRAINT [FK_memberContacts_contactType]
    FOREIGN KEY ([TypeId])
    REFERENCES [dbo].[ContactTypes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_memberContacts_contactType'
CREATE INDEX [IX_FK_memberContacts_contactType]
ON [dbo].[Contacts]
    ([TypeId]);
GO

-- Creating foreign key on [MemberId] in table 'Contacts'
ALTER TABLE [dbo].[Contacts]
ADD CONSTRAINT [FK_memberContacts_member]
    FOREIGN KEY ([MemberId])
    REFERENCES [dbo].[Members]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_memberContacts_member'
CREATE INDEX [IX_FK_memberContacts_member]
ON [dbo].[Contacts]
    ([MemberId]);
GO

-- Creating foreign key on [EventId] in table 'Participates'
ALTER TABLE [dbo].[Participates]
ADD CONSTRAINT [FK_Participate_Event]
    FOREIGN KEY ([EventId])
    REFERENCES [dbo].[Events]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Participate_Event'
CREATE INDEX [IX_FK_Participate_Event]
ON [dbo].[Participates]
    ([EventId]);
GO

-- Creating foreign key on [EventId] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [FK_Role_Event]
    FOREIGN KEY ([EventId])
    REFERENCES [dbo].[Events]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Role_Event'
CREATE INDEX [IX_FK_Role_Event]
ON [dbo].[Roles]
    ([EventId]);
GO

-- Creating foreign key on [CurrentPostionId] in table 'Members'
ALTER TABLE [dbo].[Members]
ADD CONSTRAINT [FK_Member_Position]
    FOREIGN KEY ([CurrentPostionId])
    REFERENCES [dbo].[Positions]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Member_Position'
CREATE INDEX [IX_FK_Member_Position]
ON [dbo].[Members]
    ([CurrentPostionId]);
GO

-- Creating foreign key on [UniversityId] in table 'Members'
ALTER TABLE [dbo].[Members]
ADD CONSTRAINT [FK_Member_University]
    FOREIGN KEY ([UniversityId])
    REFERENCES [dbo].[Universities]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Member_University'
CREATE INDEX [IX_FK_Member_University]
ON [dbo].[Members]
    ([UniversityId]);
GO

-- Creating foreign key on [MemberId] in table 'Participates'
ALTER TABLE [dbo].[Participates]
ADD CONSTRAINT [FK_Participate_Member]
    FOREIGN KEY ([MemberId])
    REFERENCES [dbo].[Members]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [MemberId] in table 'Quotes'
ALTER TABLE [dbo].[Quotes]
ADD CONSTRAINT [FK_Quote_Member]
    FOREIGN KEY ([MemberId])
    REFERENCES [dbo].[Members]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Quote_Member'
CREATE INDEX [IX_FK_Quote_Member]
ON [dbo].[Quotes]
    ([MemberId]);
GO

-- Creating foreign key on [MemberId] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [FK_Role_Member]
    FOREIGN KEY ([MemberId])
    REFERENCES [dbo].[Members]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [PositionId] in table 'Participates'
ALTER TABLE [dbo].[Participates]
ADD CONSTRAINT [FK_Participate_PositionType]
    FOREIGN KEY ([PositionId])
    REFERENCES [dbo].[Positions]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Participate_PositionType'
CREATE INDEX [IX_FK_Participate_PositionType]
ON [dbo].[Participates]
    ([PositionId]);
GO

-- Creating foreign key on [SenderId] in table 'Messages'
ALTER TABLE [dbo].[Messages]
ADD CONSTRAINT [FK_Message_Member]
    FOREIGN KEY ([SenderId])
    REFERENCES [dbo].[Members]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Message_Member'
CREATE INDEX [IX_FK_Message_Member]
ON [dbo].[Messages]
    ([SenderId]);
GO

-- Creating foreign key on [ThreadId] in table 'Messages'
ALTER TABLE [dbo].[Messages]
ADD CONSTRAINT [FK_Message_Thread]
    FOREIGN KEY ([ThreadId])
    REFERENCES [dbo].[Threads]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Message_Thread'
CREATE INDEX [IX_FK_Message_Thread]
ON [dbo].[Messages]
    ([ThreadId]);
GO

-- Creating foreign key on [TypeId] in table 'Threads'
ALTER TABLE [dbo].[Threads]
ADD CONSTRAINT [FK_Thread_ThreadType]
    FOREIGN KEY ([TypeId])
    REFERENCES [dbo].[ThreadTypes]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Thread_ThreadType'
CREATE INDEX [IX_FK_Thread_ThreadType]
ON [dbo].[Threads]
    ([TypeId]);
GO

-- Creating foreign key on [MemberId] in table 'Receives'
ALTER TABLE [dbo].[Receives]
ADD CONSTRAINT [FK_Recieve_Member1]
    FOREIGN KEY ([MemberId])
    REFERENCES [dbo].[Members]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Recieve_Member1'
CREATE INDEX [IX_FK_Recieve_Member1]
ON [dbo].[Receives]
    ([MemberId]);
GO

-- Creating foreign key on [MsgId] in table 'Receives'
ALTER TABLE [dbo].[Receives]
ADD CONSTRAINT [FK_Recieve_Message1]
    FOREIGN KEY ([MsgId])
    REFERENCES [dbo].[Messages]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------